package com.vasthu.core.service;

import com.vasthu.core.dao.RoleDAOImpl;
import com.vasthu.api.dao.RoleDAO;
import com.vasthu.api.domain.Role;
import com.vasthu.api.service.RoleManagerService;
import com.vasthu.gui.VstTableItemSelectable;
import com.vasthu.utility.VstDBManager;
import java.util.*;
import java.sql.*;

public class RoleManagerServiceImpl implements RoleManagerService {

    private RoleDAO roleDao;

    public RoleManagerServiceImpl() {
        roleDao = new RoleDAOImpl();
    }

    public boolean insertRole(Role role) {
        if (role == null) {
            return false;
        }
        boolean ok = roleDao.insertRole(role);
        return ok;
    }

    public boolean updatetRole(Role role) {
        if (role == null) {
            return false;
        }
        boolean ok = roleDao.updateRole(role);
        return ok;
    }

    public Role getRoleById(long roleId) {
        Role role = roleDao.getRoleById(roleId);
        return role;
    }

    public Role getRoleByName(String roleName) {
        Role role = roleDao.getRoleByName(roleName);
        return role;
    }

    public boolean deleteRoleById(long roleId) {
        boolean ok = roleDao.deleteRoleById(roleId);
        return ok;
    }

    public List<String> getAllRoleNames() {
        List<Role> roleList = new ArrayList<Role>();
        List<String> roleNameList = new ArrayList<String>();
        roleList = roleDao.getAllRoles();
        for (Role role : roleList) {
            roleNameList.add(role.getRoleName());
        }
        return roleNameList;
    }

    public List<VstTableItemSelectable> getAllRolesForTable() {
        List<Role> roleList = new ArrayList<Role>();
        List<VstTableItemSelectable> dataList = new ArrayList<VstTableItemSelectable>();
        roleList = roleDao.getAllRoles();
        for (Role role : roleList) {
            dataList.add(role);
        }
        return dataList;
    }
}